import { UserState } from '@/interfaces/api/user'
import { ResProps } from '@/interfaces/request'
import request from '@/utils/request'
import { AxiosPromise } from 'axios'

/**
 * @description: 登录接口
 */
export const userLoginApi = (data: {
  password: string
  accountNumber: string
}): AxiosPromise<ResProps<{ token: string; id: string; userName: string }>> => {
  return request({
    url: 'user/login',
    method: 'POST',
    data,
  })
}

/**
 * @description: 退出登录接口
 */
export const userUnloginApi = ({ id }: { id: number }): AxiosPromise<ResProps<null>> => {
  return request({
    url: 'user/unLogin/?id=' + id,
    method: 'POST',
  })
}

export const selectUserAllApi = (
  params: {
    accountNumber: string
    userName: string
  } = { accountNumber: '', userName: '' }
): AxiosPromise<ResProps<UserState[]>> => {
  return request({
    url: 'user/all',
    method: 'GET',
    params,
  })
}

export const updateUserApi = (data: UserState): AxiosPromise<ResProps<null>> => {
  return request({
    url: 'user/update',
    method: 'post',
    data,
  })
}

export const deleteUserApi = ({ id }: { id: number }): AxiosPromise<ResProps<null>> => {
  return request({
    url: 'user/delete/?id=' + id,
    method: 'post',
  })
}

export const addUserApi = (data: UserState): AxiosPromise<ResProps<null>> => {
  return request({
    url: 'user/add',
    method: 'post',
    data,
  })
}
